********Figure J.1 - Mexico********

*Load data and create differences
cd "$reploc/data/created_data"
use mex_full, clear

sort pid_link mxfls
foreach var of varlist rbuc_nga grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if mxfls==3 & pid_link==pid_link[_n-1]
}

*Generate cohort by birthyear variables to cluster on
gen coh_prov_clust=yearprov

*Do these results for primary sample
gen primarysample1=0
replace primarysample1=1 if rbuc_ngadif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  birthyr>=1925 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pid_link)

keep if primarysample==1

*Plot
gen income_pc_monthly=income_pc/12

local xvars income_pc_monthly NarrowBracket

foreach x in `xvars' {

*Truncate for graph
gen `x'_LB_ATRUNCATED=`x'_LB_A
gen `x'_UB_ATRUNCATED=`x'_UB_A

sum `x'_LB_A if `x'_LB_A!=-9999999
local minuse=r(min)
replace `x'_LB_ATRUNCATED=0 if `x'_LB_A<0
replace `x'_LB_ATRUNCATED=5 if `x'_LB_A>5

sum `x'_UB_A if `x'_UB_A!=9999999
local maxuse=r(max)
replace `x'_UB_ATRUNCATED=5 if `x'_UB_A>5
replace `x'_UB_ATRUNCATED=0 if `x'_UB_A<0

forval mxflsi=2/3 {

if "`x'"!="NarrowBracket" {

*For graph, drop outliers
sum `x', d
drop if `x'>r(p99)
drop if `x'<0

local nam1 HH Income per capita

if "`mxflsi'"=="2" {

twoway (rspike `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==1 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==2 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==3 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==4 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==5 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==6 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==7 & mxfls==`mxflsi', msize(vsmall)), ytitle("Range of Struct. Risk Aversion Parameter") xtitle(" `nam1' (Pesos)") legend(label(1 "Risk Av. Bucket 1") label(2 "Risk Av. Bucket 2") label(3 " Risk Av. Bucket 3") label(4 " Risk Av. Bucket 4") label(5 " Risk Av. Bucket 5") label(6 " Risk Av. Bucket 6") label(7 " Risk Av. Bucket 7")) graphregion(color(white))

cd "$reploc/results"
graph export figureJ1MexicoBroadmxfls`mxflsi'.eps, replace

}

if "`mxflsi'"=="3" {
twoway (rspike `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==1 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==2 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==3 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==4 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==5 & mxfls==`mxflsi', msize(vsmall)), ytitle("Range of Struct. Risk Aversion Parameter") xtitle(" `nam1' (Pesos)") legend(label(1 "Risk Av. Bucket 1") label(2 "Risk Av. Bucket 2") label(3 " Risk Av. Bucket 3") label(4 " Risk Av. Bucket 4") label(5 " Risk Av. Bucket 5")) graphregion(color(white))

cd "$reploc/results"
graph export figureJ1MexicoBroadmxfls`mxflsi'.eps, replace

}
}


else{

if "`mxflsi'"=="2" {
capture drop id
gen id=_n
twoway (rspike `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==1 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==2 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==3 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==4 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==5 & mxfls==`mxflsi', msize(vsmall))  (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==6 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==7 & mxfls==`mxflsi', msize(vsmall)), ytitle("Range of Structural Risk Aversion Parameter") xtitle("ID") legend(label(1 "Risk Av. Bucket 1") label(2 "Risk Av. Bucket 2") label(3 " Risk Av. Bucket 3") label(4 " Risk Av. Bucket 4") label(5 " Risk Av. Bucket 5") label(6 " Risk Av. Bucket 6") label(7 " Risk Av. Bucket 7")) graphregion(color(white))
graph export figureJ1MexicoNarrowmxfls`mxflsi'.eps, replace

}


if "`mxflsi'"=="3" {
capture drop id
gen id=_n
twoway (rspike `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==1 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==2 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==3 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==4 & mxfls==`mxflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==5 & mxfls==`mxflsi', msize(vsmall)), ytitle("Range of Structural Risk Aversion Parameter") xtitle("ID") legend(label(1 "Risk Av. Bucket 1") label(2 "Risk Av. Bucket 2") label(3 " Risk Av. Bucket 3") label(4 " Risk Av. Bucket 4") label(5 " Risk Av. Bucket 5")) graphregion(color(white))
graph export figureJ1MexicoNarrowmxfls`mxflsi'.eps, replace

}

}

}
}

